function TagsFilter(fromCookie) {

	var self = this;
	this.tags = {};
	if(fromCookie) {
		var tagsCookie = $.cookie('trFilterTags');
		if(tagsCookie != null) {
			$.each(JSON.parse(tagsCookie), function(index, tagId) {
				self.tags[tagId] = tagId;
			});
		}
	}

	this.toggle = function(tagId) {
		if(tagId in this.tags) {
			delete this.tags[tagId];
		} else {
			this.tags[tagId] = tagId;
		}
		this.onChange();
		return (tagId in this.tags);
	};

	this.onChange = function() {
		$.cookie('trFilterTags', JSON.stringify(Object.keys(this.tags)));
		$(this).trigger('change');
	};

	this.filter = function(tagsMap) {
		var changed = false;
		for(var tagId in this.tags) {
			if(!(tagId in tagsMap)) {
				delete this.tags[tagId];
				changed = true;
			}
		}
		if(changed) {
			this.onChange();
		}
	};

	this.isToggled = function(tagId) {
		return (tagId in this.tags);
	};

	this.getValue = function() {
		return Object.keys(this.tags);
	};
};